<?php 
		$roomno = $_GET['showroom'];
		$username = $_SESSION['username'];        $query = "select * from user where username='$username'";        $result = mysql_query($query);

		if (!$result) {
  				  echo '<script>						<!-- 						 window.location= "http://www.mariokartchallenger.com"									//-->						</script>'; die();		}

		$user = mysql_fetch_array($result);
		$temp = $user['nick']; 
		$gamecode = $user['gamecode']; 
		if (empty($gamecode) && is_authed()) { include 'gamecode.php'; exit();};
?>

<table height="320" width="603px">
				<tr><td id="info" valign="top">
					<table cellpadding="0" cellspacing="0" >
						<tr><td width="395px" valign="top"><?php include 'navbar.php' ?>						</td>
						<td>&nbsp;</td>
						<td valign="top">
							<table cellpadding="0" cellspacing="0" border="0" align="right" width="185px">
								<tr><td>
									<?php if (empty($temp)) { include 'guestgreet.php'; } else{ include 'usergreet.php'; } ?>
								</td></tr>
								<tr><td id="login">
									<div align="right"><span style="font-size:12px"><? echo $user['nick']; ?></span> ( <strong><?php if (is_authed()) { echo '<a href="index.php?act=logout">Logout</a>';} else {echo '<a href="register.php">Register</a> | <a href="index.php">Log In</a> ';} ?> </strong> )</div>
								</td></tr>
							</table>
					

						</td></tr>
					</table>
					<?php $query = "select * from gamematch where id='$roomno'";         				  $result = mysql_query($query); 
						  $roomstuff = mysql_fetch_array($result); 
					      $host = $roomstuff['host'];
						  $descript = $roomstuff['descr'];
						  $query = "select * from user where username='$host'";         				  $result = mysql_query($query);
						  $hostdata = mysql_fetch_array($result); 

					?>
					<table cellpadding="0" cellspacing="0"><tr><td width="385px" valign="top" >	
						<div>						<b class="inbox">						<b class="inbox1"><b></b></b>						<b class="inbox2"><b></b></b>						<b class="inbox3"></b>						<b class="inbox4"></b>						<b class="inbox5"></b></b>						<div class="inboxfg">				
						<table border="0" width="385">
							<tr><td id="buenos" valign="top">

 									<table cellpadding="0" cellspacing="0"><tr><td align="center" valign="top" width="75px">
										<table cellpadding="0" cellspacing="0" height="100%">
											<tr><td valign="top" height="50%">
												<img style="border:1px solid black" src="avatar/<?php echo $hostdata['racer']; ?>.jpg" />
											</td></tr>
											<tr><td valign="middle" align="center" height="50%">
												<?php if ($roomstuff['gametype'] == 'battle') { 
														if (!empty($descript)) { echo ''; } 
														echo '<p style="padding-top:5px"><strong><span style="font-size:14px">' . $hostdata['battlevr'] . '</span><span style="font-size:10px">VR</span></strong>'; } 
													else { 
														if (!empty($descript)) { echo ''; } 
														echo '<p style="padding-top:5px"><strong><span style="font-size:14px">' . $hostdata['racevr'] . '</span><span style="font-size:10px">VR</span></strong>'; } 
												?>
											</tr></td>
										</table>
									</td><td valign="top" align="right" width="300">
										<?php 
											$friendcode=$hostdata['gamecode']; 
											if ($username != $hostdata['username']) { 
												stringtoarray($friendcode); 
												echo '<h3><div align="right">FRIENDCODE: ' . $friendcode[0] . $friendcode[1] . $friendcode[2] . $friendcode[3] . '-'. $friendcode[4] . $friendcode[5] . $friendcode[6] . $friendcode[7] . '-'. $friendcode[8] . $friendcode[9] . $friendcode[10] . $friendcode[11], '</div></h3><span style="font-size:10px">';
												if ($roomstuff['descr'] != '') { echo $roomstuff['descr'], '<br />';}
												echo 'hosted by <a href="index.php?showuser='. $hostdata['userid']. '" >' . $hostdata['nick']. '</a>'; } 
											else { 
												echo '<h3><div align="right">ADD THE FRIENDCODES BELOW</div></h3>'; 
											} 
										?></span><br /><br /><span style="font-size:10pt; color #000000"><?php 
										$seat2 = $roomstuff['seat2'];
										$seat3 = $roomstuff['seat3'];
										$seat4 = $roomstuff['seat4'];
										$seat5 = $roomstuff['seat5'];

									    $query = "select * from user where username='$seat2'";			         				    $result = mysql_query($query);
										$seat2data = mysql_fetch_array($result);
			
									    $query = "select * from user where username='$seat3'";         							    $result = mysql_query($query);
										$seat3data = mysql_fetch_array($result);

									    $query = "select * from user where username='$seat4'";			         				    $result = mysql_query($query);
										$seat4data = mysql_fetch_array($result);

									    $query = "select * from user where username='$seat5'";			         				    $result = mysql_query($query);
										$seat5data = mysql_fetch_array($result);

										$seat2prop = $seat2data[gamecode];
										$seat3prop = $seat3data[gamecode];
										$seat4prop = $seat4data[gamecode];
										$seat5prop = $seat5data[gamecode];

										$seat2img = $seat2data[racer] . '_thumb';
										$seat3img = $seat3data[racer] . '_thumb';
										$seat4img = $seat4data[racer] . '_thumb';
										$seat5img = $seat5data[racer] . '_thumb';

										if ($seat2img == '_thumb') { $seat2img = 'noone'; }
										if ($seat3img == '_thumb') { $seat3img = 'noone'; }	
										if ($seat4img == '_thumb') { $seat4img = 'noone'; }
										if ($seat5img == '_thumb') { $seat5img = 'noone'; }

										$seat2nick = $seat2data[nick];
										$seat3nick = $seat3data[nick];
										$seat4nick = $seat4data[nick];
										$seat5nick = $seat5data[nick];

										$seat2id = $seat2data[userid];
										$seat3id = $seat3data[userid];
										$seat4id = $seat4data[userid];
										$seat5id = $seat5data[userid];

										if ($seat2nick == '') { $seat2nick = '&nbsp;'; }
										if ($seat3nick == '') { $seat3nick = '&nbsp;'; }	
										if ($seat4nick == '') { $seat4nick = '&nbsp;'; }
										if ($seat5nick == '') { $seat5nick = '&nbsp;'; }

										stringtoarray($seat2prop);
										stringtoarray($seat3prop);
										stringtoarray($seat4prop);
										stringtoarray($seat5prop);

										$seat2prop = $seat2prop[0] . $seat2prop[1] . $seat2prop[2] . $seat2prop[3] . '-'. $seat2prop[4] . $seat2prop[5] . $seat2prop[6] . $seat2prop[7] . '-'. $seat2prop[8] . $seat2prop[9] . $seat2prop[10] . $seat2prop[11];

										$seat3prop = $seat3prop[0] . $seat3prop[1] . $seat3prop[2] . $seat3prop[3] . '-'. $seat3prop[4] . $seat3prop[5] . $seat3prop[6] . $seat3prop[7] . '-'. $seat3prop[8] . $seat3prop[9] . $seat3prop[10] . $seat3prop[11];

										$seat4prop = $seat4prop[0] . $seat4prop[1] . $seat4prop[2] . $seat4prop[3] . '-'. $seat4prop[4] . $seat4prop[5] . $seat4prop[6] . $seat4prop[7] . '-'. $seat4prop[8] . $seat4prop[9] . $seat4prop[10] . $seat4prop[11];

										$seat5prop = $seat5prop[0] . $seat5prop[1] . $seat5prop[2] . $seat5prop[3] . '-'. $seat5prop[4] . $seat5prop[5] . $seat5prop[6] . $seat5prop[7] . '-'. $seat5prop[8] . $seat5prop[9] . $seat5prop[10] . $seat5prop[11];


										$friendcode=$hostdata['gamecode']; 
										if ($username != $hostdata['username']) { 
											echo '<table cellpadding = "0" cellspacing= "0">
													<tr><td>
														<table cellpadding = "0" cellspacing= "0" style="padding-right:14px">
															<tr><td>
																<div align="center"><img style="border: 1px solid black" src="avatar/' . $seat2img . '.jpg"></div>
															</td></tr>
															<tr><td><div align="center"><span style="font-size:10px"><a href="index.php?showuser='. $seat2id . '">'. $seat2nick .'</a></span></div>
															</td></tr>
														</table>
													</td><td>
														<table cellpadding = "0" cellspacing= "0" style="padding-right:14px">
															<tr><td>
																<div align="center"><img style="border: 1px solid black" src="avatar/' . $seat3img . '.jpg"></div>
															</td></tr>
															<tr><td><div align="center"><span style="font-size:10px"><a href="index.php?showuser='. $seat3id . '">' . $seat3nick .'</a></span></div>
															</td></tr>
														</table>
													</td><td>
														<table cellpadding = "0" cellspacing= "0" style="padding-right:14px">
															<tr><td>
																<div align="center"><img style="border: 1px solid black" src="avatar/' . $seat4img . '.jpg"></div>
															</td></tr>
															<tr><td><div align="center"><span style="font-size:10px"><a href="index.php?showuser='. $seat4id . '">' . $seat4nick .'</a></span></div>
															</td></tr>
														</table>
													</td><td>
														<table cellpadding = "0" cellspacing= "0">
															<tr><td>
																<div align="center"><img style="border: 1px solid black" src="avatar/' . $seat5img . '.jpg"></div>
															</td></tr>
															<tr><td><div align="center"><span style="font-size:10px"><a href="index.php?showuser='. $seat5id . '">' . $seat5nick .'</a></span></div>
															</td></tr>
														</table>
													</td><td>
												  </table>';
										 } 
										else { 
											echo '<a href="index.php?showuser='. $seat2data['userid'] .'">'.$seat2data['nick'].'</a>' . '   ' . $seat2prop.'<br />';
											echo '<a href="index.php?showuser='. $seat3data['userid'] .'">'.$seat3data['nick'].'</a>' . '   ' . $seat3prop.'<br />';
											echo '<a href="index.php?showuser='. $seat4data['userid'] .'">'.$seat4data['nick'].'</a>' . '   ' . $seat4prop.'<br />';
											echo '<a href="index.php?showuser='. $seat5data['userid'] .'">'.$seat5data['nick'].'</a>' . '   ' . $seat5prop.'<br />';
										} 





										
 ?> 
							
							</span> </td></tr></table>
							</td>
							<td valign="top" align="right"></td></tr>
						</table>
						
					  	</div>  						<b class="inbox">  						<b class="inbox5"></b>  						<b class="inbox4"></b>  						<b class="inbox3"></b>  						<b class="inbox2"><b></b></b>  						<b class="inbox1"><b></b></b></b>						</div>


						<table align="center" style="padding-top:10px" cellpadding="0" cellspacing="0" width="380" border="0">
							<tr><td align="left" valign="bottom"><img src="img/comments.png" /></td>
							<td width="130px" align="left" style="padding-left:5px"><span style="font-size:10px"><strong><a href="index.php?viewcomments=<? echo $roomno; ?>">Game Comments</a></strong></span></td>
							<td valign="top" width="255" align="right" valign="top">
								<h3><div align="right"><?php echo $roomstuff['battlename']; ?></div></h3>
								<span style="font-size:8pt"><strong><a href="http://www.google.com/search?q=what+time+is+it"><?php echo $roomstuff['matchdate'].' - '; $cleantime = date("gA", strtotime($roomstuff['matchtime']));  echo $cleantime; ?> (CDT)</a></strong></span>
							</td></tr>
							<tr><td>&nbsp;</td>
							<td>&nbsp;</td>
							<td valign="top" style="padding-top : 5px">
									<?php 	
									$exp_date = $roomstuff['matchdate']; 
									$todays_date = date("Y-m-d"); 
									$today = strtotime($todays_date); 
									$expiration_date = strtotime($exp_date); 
									//echo $today, ' ', $expiration_date, ' ', strtotime($roomstuff['matchtime']);
									if ($expiration_date < $today) { $expired = "yes"; } else { $expired = "no"; } 		

									if (is_joined($username, $roomno) || !is_authed()) {     																	} elseif (!isset($_POST['submit']) && empty($roomstuff['seat5']) &&  $expired == "no") {     									include 'joinroom_form.inc.php';									}
						
									if (isset($_POST['submit']) && empty($seat2data) && !is_joined($username, $roomno)) { 										 $query = "update gamematch set seat2='$username' where id='$roomno'"; mysql_query ($query); email_match($roomstuff['host'], $user['gamecode'], $user['nick'], $roomstuff['battlename'], $roomstuff['matchtime']);  echo '<script>							<!-- 								 window.location= "http://www.mariokartchallenger.com/index.php?showroom='. $roomno .'"							//-->							</script>';}
									 elseif (isset($_POST['submit']) && empty($seat3data) && !is_joined($username, $roomno))  { 										 $query = "update gamematch set seat3='$username' where id='$roomno'"; mysql_query ($query); email_match($roomstuff['host'], $user['gamecode'], $user['nick'], $roomstuff['battlename'], $roomstuff['matchtime']);echo '<script>							<!-- 								 window.location= "http://www.mariokartchallenger.com/index.php?showroom='. $roomno .'"							//-->							</script>'; }
									 elseif (isset($_POST['submit']) && empty($seat4data) && !is_joined($username, $roomno))  { 										 $query = "update gamematch set seat4='$username' where id='$roomno'"; mysql_query ($query); email_match($roomstuff['host'], $user['gamecode'], $user['nick'], $roomstuff['battlename'], $roomstuff['matchtime']);echo '<script>							<!-- 								 window.location= "http://www.mariokartchallenger.com/index.php?showroom='. $roomno .'"							//-->							</script>'; }
									 elseif (isset($_POST['submit']) && empty($seat5data) && !is_joined($username, $roomno))  { 										 $query = "update gamematch set seat5='$username' where id='$roomno'"; mysql_query ($query); email_match($roomstuff['host'], $seat5data['gamecode'], $seat5data['nick'], $roomstuff['battlename'], $roomstuff['matchtime']);echo '<script>							<!-- 								 window.location= "http://www.mariokartchallenger.com/index.php?showroom='. $roomno .'"							//-->							</script>'; }
									 else { $joinroom_error ="couldn't add you to a seat"; }
								
							 ?>
							 </td></tr>
							</table>


					</td><td valign="top">
                          <div align="right">
							<?php
                            if (is_authed()) { include 'sidebar.php';} elseif (!is_authed()) { echo '' ;} ?>						</div>
					</td>

					</tr></table>
				
					</td></tr>
			</table>
			</td>
		</tr>
	</table>
<?php include 'footer.php'; ?>